//
//  HotCellDetailOfSounds.m
//  SuperRadio
//
//  Created by Damon on 14/12/19.
//  Copyright (c) 2014年 三个臭皮匠. All rights reserved.
//

#import "HotCellDetailOfSounds.h"
#import "Sounds.h"
#import "UIImageView+WebCache.h"
@interface HotCellDetailOfSounds ()

@property (nonatomic, retain) UIImageView * coverSmall;
@property (nonatomic, retain) UIImageView * playImageView;
@property (nonatomic, retain) UILabel *soundTitle;
@property (nonatomic, retain) UIImageView *playCountsImageView;
@property (nonatomic, retain) UILabel *playCounts;

@end

@implementation HotCellDetailOfSounds


// 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.coverSmall = [[UIImageView alloc] init];
        [self addSubview:self.coverSmall];
        [_coverSmall release];
        
        self.playImageView = [[UIImageView alloc] init];
        [self addSubview:self.playImageView];
        [_playImageView release];
        
        self.playCountsImageView  = [[UIImageView alloc] init];
        [self addSubview:self.playCountsImageView];
        [_playCountsImageView release];
        
        self.soundTitle = [[UILabel alloc] init];
        [self addSubview:self.soundTitle];
        [_soundTitle release];
        
        self.playCounts = [[UILabel alloc] init];
        [self addSubview:self.playCounts];
        [_playCounts release];
        
        
    }
    
    return self;
}

// 重写setter方法
- (void)setSounds:(Sounds *)sounds
{
    if (_sounds != sounds) {
        [_sounds release];
        _sounds = [sounds retain];
    }
    self.playCounts.text = [sounds.playsCounts description];
    [self.coverSmall setImageWithURL:[NSURL URLWithString:[sounds.coverSmall stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    self.soundTitle.text = sounds.title;
    
}


// 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    NSInteger height = self.frame.size.height / 5;
    NSInteger width = self.frame.size.width;
    self.coverSmall.frame = CGRectMake(0, 0, width, height * 3);
    self.soundTitle.frame = CGRectMake(0, height * 3, width, height * 1);
    self.playCounts.frame = CGRectMake(0, height * 4, width, height * 1);

}


// 释放
- (void)dealloc
{
    [_playImageView release];
    [_playCountsImageView release];
    [_playCounts release];
    [_coverSmall release];
    [_soundTitle release];
    [_sounds release];
    [super dealloc];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
